<template>
	<view >
		<uni-section title="招聘信息完善" type="line"></uni-section>
		<view class="p15">
			<uni-forms label-position="top" ref="baseForm" :modelValue="form" label-width="120">
				<uni-forms-item label="招聘类型:" required>
					<uni-data-select v-model="form.recruit_type" :localdata="type"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="职位名称:" required>
					<uni-easyinput v-model="form.title" placeholder="请输入职位名称" />
				</uni-forms-item>
				<uni-forms-item label="工作地区:" required>
					<picker @change="onRegionChange" :value="form.region" mode="region">
						<slot>
							<div class="region">
								{{form.province}} - {{form.city}} - {{form.areas}}
							</div>
						</slot>
					</picker>
				</uni-forms-item>
				<uni-forms-item label="工作地址:" required>
					<uni-easyinput v-model="form.address" placeholder="请输入工作地址" />
				</uni-forms-item>
				<uni-forms-item label="职位描述:" required>
					<uni-easyinput type="textarea" v-model="form.content" placeholder="请输入职位描述" />
				</uni-forms-item>
				<uni-forms-item label="经验:" required>
					<uni-data-select v-model="form.experience" :localdata="exp"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="学历:" required>
					<uni-data-select v-model="form.education" :localdata="edu"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="薪资类型:" required>
					<uni-data-select v-model="form.salary_type" :localdata="scale"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="薪资范围:" required>
					<uni-data-select v-if="form.salary_type == 1" v-model="form.salary" :localdata="year_wages"></uni-data-select>
					<uni-data-select v-else v-model="form.salary" :localdata="month_wages"></uni-data-select>
				</uni-forms-item>
			</uni-forms>
			<button class="default-button" @click="save()">保存</button>
			<button v-if="id > 0" class="mt15" @click="onDelete()">删除</button>
		</view>
		
		<uni-popup ref="popup" background-color="#fff" style="width: 0%; margin: 0 auto;">
			<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="删除确认" content="删除后不可撤回,确认要删除么?" @confirm="dialogConfirm" @close="dialogClose">
				<view class="p8">
					<uni-title type="h5" title="删除后不可撤回,确认要删除么?"></uni-title>
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:0,
				form:{
					title:'',
					province:'请选择',
					city:'请选择',
					areas:'请选择',
					address:'',
					recruit_type:0,
					content:'',
					experience:0,
					education:0,
					salary_type:1,
					salary:1,
				},
				logo:{name:"company-logo.png",extname:"png",url:"https://xinzhu-1301398555.cos.ap-shanghai.myqcloud.com/wxapp/company-logo.png"},
				welfares:[],
				type:[],
				scale:[{text:'年薪',value:1},{text:'月薪',value:2}],
				year_wages:[],
				month_wages:[],
				edu:[],
				exp:[]
			}
		},
		onShow() {
			this.type = this.$func.map_arr(this.$func.type)
			this.exp = this.$func.map_arr(this.$func.exp)
			this.edu = this.$func.map_arr(this.$func.edu)
			this.month_wages = this.$func.map_arr(this.$func.month_wages)
			this.year_wages = this.$func.map_arr(this.$func.year_wages)
			// https://adminapi.xinzhuvip.com/api/applet_api/recruit_company_info
			// https://adminapi.xinzhuvip.com/api/applet_api/recruit
			// https://adminapi.xinzhuvip.com/api/applet_api/recruit_delete
			// recruit_edit
			// recruit_columns
			// 'https://adminapi.xinzhuvip.com/api/applet_api/recruit_info/' + this.data.id;
		},
		onLoad(options){
			this.id = options.id
			if(this.id > 0){
				this.onGetData()
			}
		},
		methods: {
			save(){
				let _this = this
				if(!this.form.recruit_type){
					uni.showToast({title: '请选择招聘类型',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.title){
					uni.showToast({title: '请输入职位名称',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.areas){
					uni.showToast({title: '请选择地区',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.address){
					uni.showToast({title: '请输入地址',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.content){
					uni.showToast({title: '请输入职位介绍',icon: 'error',duration: 2000})
					return;
				}
				this.form.id = this.id
				this.$request_api('applet_api/recruit_edit','POST',this.form).then(res => {
					if(res.code == 200){
						uni.showToast({title: '职位发布成功',icon: 'success',duration: 2000})
						_this.confirmPush()
						return;
					}
					
					uni.showToast({title: res.msg,icon: 'error',duration: 2000})
					return;
				}).catch(err => {
					console.log(err)
				})
			},
			onGetData(){
				let _this = this
				this.$request_api('applet_api/recruit_info/'+_this.id,'POST',{}).then(res => {
					_this.form = res.data
				}).catch(err => {
					console.log(err)
				})
			},
			onDelete(){
				this.$refs.popup.open('center')
			},
			dialogConfirm(){
				let _this = this
				this.$request_api('applet_api/recruit_delete','POST',{id:this.id}).then(res => {
					_this.confirmPush()
				}).catch(err => {
					console.log(err)
				})
			},
			dialogClose(){
				
			},
			confirmPush(e){
				let _this = this
				uni.navigateTo({
					url: '/user/recruit/recruit'
				});
			},
			onRegionChange(e){
				let _this = this
				_this.form.province = e.detail.value[0],
				_this.form.city = e.detail.value[1],
				_this.form.areas = e.detail.value[2]
			},
		}
	}
</script>

<style>
.region{border: 1px solid #e5e5e5;font-size: 12px;height: 35px;line-height: 35px;padding-left: 8px;color: #6a6a6a;}
</style>
